<!DOCTYPE html>
<c:if test="${reimburse.act.finishTask != true}">
	<div class="rowSubmit">
		<c:if test="${reimburse.task.taskDefinitionKey=='boosAudit'}">
			<a href="javascript:void(0)" onclick="complete([{key: 'boosPass',value: true,type: 'B'}])" class="btn btn-alt btn-blue"><span>同意</span></a>
			<a href="javascript:void(0)" onclick="complete('${reimburse.task.id}', '${reimburse.task.processInstanceId}', [{key: 'boosPass',value: false,type: 'B'}])" class="btn btn-alt btn-yellow"><span>不同意</span></a>
		</c:if>
		<c:if test="${reimburse.task.taskDefinitionKey=='modifyApply'}">
			<a href="javascript:void(0)" onclick="update('${reimburse.task.id}', '${reimburse.task.processInstanceId}', [{key: 'reApply',value: true,type: 'B'}])" class="btn btn-alt btn-blue"><span>再试试</span></a>
			<a href="javascript:void(0)" onclick="complete('${reimburse.task.id}', '${reimburse.task.processInstanceId}', [{key: 'reApply',value: false,type: 'B'}])" class="btn btn-alt btn-yellow"><span>放弃了</span></a>
		</c:if>
		<c:if test="${reimburse.task.taskDefinitionKey=='confirmMoney'}">
			<a href="javascript:void(0)" onclick="complete('${reimburse.task.id}', '${reimburse.task.processInstanceId}', [])" class="btn btn-alt btn-blue"><span>确认收款</span></a>
		</c:if>
	</div>

	<script type="text/javascript">
		var layer;
		var iframeWin = null,
			iframeBody = null;

		function start(variables) {
			loadi = layer.load(2, {
				shade: layerLoadShade,
				time: layerLoadMaxTime
			});
			var keys = "",
				values = "",
				types = "";
			if(variables) {
				$.each(variables, function(idx) {
					if(keys != "") {
						keys += ",";
						values += ",";
						types += ",";
					}
					keys += this.key;
					values += this.value;
					types += this.type;
				});
				$('#keys').val(keys);
				$('#values').val(values);
				$('#types').val(types);
			}
			var url = "${ctx}/reimburse/start";
			var formData = new FormData($('#dataForm')[0]);
			$.ajax({
				cache: false,
				type: "POST",
				url: url,
				data: formData,
				processData: false,
				contentType: false,
				error: function(request) {
					layer.close(loadi);
				},
				success: function(data) {
					layer.close(loadi);
					layer.msg("操作成功！", {
						offset: 'rb',
						icon: 6,
						shift: 8,
						time: layerMsgTime
					});
					goBackToList();
				}
			});
		}

		/**
		 * 办理任务
		 * @param {Object} taskId
		 */
		function complete(taskId, procInsId, variables) {
			// 转换JSON为字符串
			var keys = "",
				values = "",
				types = "";
			if(variables) {
				$.each(variables, function(idx) {
					if(keys != "") {
						keys += ",";
						values += ",";
						types += ",";
					}
					keys += this.key;
					values += this.value;
					types += this.type;
				});
			}
			// 发送任务完成请求
			loadi = layer.load(2, {
				shade: layerLoadShade,
				
				
				
				
			$.post('${ctx}/actTask/complete/', {
				taskId: taskId,
				procInsId: procInsId,
				"comment": $('#comment').val(),
				"vars.keys": keys,
				"vars.values": values,
				"vars.types": types
			}, function(data) {
				layer.close(loadi);
				layer.msg("发送成功！", {
					icon: 6,
					time: layerMsgTime
				});
				goBackToList();
			});
		}

		function update(taskId, procInsId, variables) {
			loadi = layer.load(2, {
				shade: layerLoadShade,
				time: layerLoadMaxTime
			});
			var url = "${ctx}/reimburse/update";
			$.ajax({
				cache: true,
				type: "POST",
				url: url,
				data: $('#dataForm').serialize(),
				async: false,
				error: function(request) {
					layer.close(loadi);
				},
				success: function(data) {
					layer.close(loadi);
					complete(taskId, procInsId, variables);
				}
			});
		}

		function goBackToList() {
			//window.close();
			history.go(-1);
		}
	</script>
	</body>

	</html>